<?php
//引入php QR库文件
include_once('phpqrcode.php');

$code = isset($_REQUEST['code'])?$_REQUEST['code']:'';
if($code==''){
	die('code err');
}

//当前目录
$dir = "plugins/phpqrcode/";
//跳转地址 
$dres = "http://".$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')+1);
$path = str_replace($dir,"",$dres);
$url  = $path.'wx_login.php?type=1&qrcode='.$code;

//图片路径
$img_path = './../../images/QRimg/';

$errorCorrentionLevel = 'M'; //容错级别
$matrixPoinSize = 10; //生成图片大小


$logo_path 	= $img_path.'logo.jpg'; //logo
$QR_path 	= $img_path.'qrcode.png'; //已经生成的二维码

//生成二维码,第二个参数为二维码保存路径
QRcode::png($url,$QR_path ,$errorCorrentionLevel,$matrixPoinSize,2);




if(!file_exists($logo_path)){
	die('路径错误');
}

 
$QR = imagecreatefromstring(file_get_contents($QR_path)); 
$logo = imagecreatefromstring(file_get_contents($logo_path));   
$QR_width = imagesx($QR);//二维码图片宽度   
$QR_height = imagesy($QR);//二维码图片高度   
$logo_width = imagesx($logo);//logo图片宽度   
$logo_height = imagesy($logo);//logo图片高度   
$logo_qr_width = $QR_width / 5;   
$scale = $logo_width/$logo_qr_width;   
$logo_qr_height = $logo_height/$scale;   
$from_width = ($QR_width - $logo_qr_width) / 2;   
//重新组合图片并调整大小   
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,   
$logo_qr_height, $logo_width, $logo_height);   

header("Content-type: image/png");
//输出图片   
imagepng($QR);
imagedestroy($QR); 